/**
 * 这是 city 模块
 */

export default {
  // 命名空间，建议每个子模块都需要配置
  namespaced: true,

  state() {
    return {
      cities: []
    }
  },

  getters: {
    cityLength(state) {
      return state.cities.length
    },

    gender() {
      return 'hello'
    }
  },

  mutations: {
    setCities(state, payload) {
      state.cities = payload
    },

    sayHi() {
      console.log('city sayHi')
    }
  },

  actions: {
    getCities(context, payload) {
      fetch('https://m.maizuo.com/gateway?k=4914189', {
        headers: {
          'X-Host': 'mall.film-ticket.city.list'
        }
      })
        .then((response) => response.json())
        .then((result) => {
          console.log('result', result)
          // ...
        })
    },

    sayHi() {
      console.log('city sayHi action')
    }
  }

  // 子模块是否可以也有子模块。可以，但没必要
  // modules: {

  // }
}
